<template>
  <div class="search-list">
    <van-nav-bar class="navBar" left-arrow @click-left="onClickLeft">
      <template #title>
        <span class="title">文章搜索列表</span>
      </template>
      <template #left>
        <span class="left iconfont">&#xe637;</span>
      </template>
    </van-nav-bar>
    <div class="content">
      <div class="item" v-for="(item, index) in searchList" :key="index">
        <div v-if="item.cover.images.length === 0">
          <div class="top">
            <h4 class="title">{{ item.title }}</h4>
          </div>
          <div class="middle height"></div>
        </div>
        <div v-else-if="item.cover.images.length === 3">
          <div class="top">
            <h4 class="title">{{ item.title }}</h4>
          </div>
          <div class="middle">
            <img
              v-image="imageUrl"
              v-for="(item1, index1) in item.cover.images"
              :key="index1"
              :src="item1"
            />
          </div>
        </div>
        <div class="item1" v-else>
          <div class="top top1">
            <h4 class="title">{{ item.title }}</h4>
          </div>
          <div class="middle1">
            <img
              v-for="(item1, index1) in item.cover.images"
              v-image="imageUrl"
              :key="index1"
              :src="item1"
            />
          </div>
        </div>
        <div class="bottom">
          <div class="userName">{{ item.aut_name }}</div>
          <div class="comment">{{ item.comm_count + 111 }}条评论</div>
          <div class="time">{{ item.pubdate }}</div>
          <div @click="showPopup = true" class="iconfont">
            &#xe605;
          </div>
        </div>
      </div>
    </div>
    <van-popup
      v-model="showPopup"
      round
      position="center"
      :style="{ height: '24%', width: '85%' }"
      class="popup"
    >
      <div>
        <div class="reverse"><i class="iconfont">&#xe639;</i></div>
        <span>不感兴趣</span>
      </div>
      <div class="callBack">
        <div><span class="iconfont">&#xe640;</span></div>
        <span>反馈垃圾内容</span>
        <div class="arrow">
          <i class="iconfont">&#xe653;</i>
        </div>
      </div>
      <div>
        <div><span class="iconfont">&#xe607;</span></div>
        <span>拉黑作者</span>
      </div>
    </van-popup>
    <van-popup>
      <van-cell-group>
        <van-cell title="单元格" value="内容" />
        <van-cell title="单元格" value="内容" label="描述信息" />
      </van-cell-group>
    </van-popup>
  </div>
</template>

<script>
import { search } from '@/api/search'
export default {
  data () {
    return {
      searchList: [],
      keyWord: this.$route.query.keyWord,
      imageUrl: require('@/assets/logo.png'),
      showPopup: false
    }
  },
  created () {
    search({ q: this.keyWord }).then(res => {
      console.log(res)
      res.data.results.forEach(item => {
        item.pubdate = item.pubdate.split('T').join('  ')
      })
      this.searchList = res.data.results
    })
  },
  methods: {
    onClickLeft () {
      this.$router.push('/home/search')
    }
  }
}
</script>

<style lang="less" scoped>
.search-list {
  padding-bottom: 10px;
  .navBar {
    background-color: #f699b4;

    ::v-deep .van-nav-bar__left {
      padding: 0;
      .left {
        color: #fff;
        font-size: 50px;
      }
    }

    .title {
      color: #f3f3f3;
    }
  }
  .content {
    padding: 0 15px;
    .item {
      margin-top: 10px;
      border-bottom: 1px solid #ddd;
      padding-bottom: 10px;
      .top {
        margin-bottom: 10px;
        .title {
          text-overflow: ellipsis;
          display: -webkit-box;
          -webkit-line-clamp: 2;
          -webkit-box-orient: vertical;
          overflow: hidden;
          font-size: 18px;
        }
      }

      .middle {
        display: flex;
        justify-content: space-between;
        img {
          height: 60px;
          width: 110px;
        }
      }

      .height {
        height: 30px;
      }
      .bottom {
        display: flex;
        margin-top: 5px;
        color: #bbb4b4;
        justify-content: space-between;
        align-items: center;
        font-size: 14px;
        .userName {
          width: 90px;
        }
        .comment {
          margin-right: 20px;
        }
        .time {
          flex: 1;
        }
      }
    }
    .item1 {
      display: flex;
      padding: 5px;
      justify-content: space-between;
      .middle1 {
        text-align: right;
        margin-left: 10px;
        img {
          height: 80px;
          width: 130px;
        }
      }
    }
  }
  .popup {
    padding: 10px 20px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    div {
      height: 30px;
      line-height: 30px;
      display: flex;
      .iconfont {
        color: #646566;
        font-size: 25px;
      }
      .reverse {
        transform: rotate(180deg);
      }
      span:nth-child(2) {
        font-weight: 700;
        margin-left: 10px;
        color: #646566;
      }
    }
    .callBack {
      flex: 1;
      padding: 10px 0;
      border-top: 1px solid #eee;
      border-bottom: 1px solid #eee;
      position: relative;
      .arrow {
        position: absolute;
        height: 35px;
        width: 60px;
        text-align: center;
        border: 2px solid #ccc;
        border-radius: 20px;
        right: 0;
        top: 7px;
        margin: 0 auto;
        padding-left: 17px;
      }
    }
  }
}
</style>
